package com.bonc.modules.business.controller;

import java.io.UnsupportedEncodingException;
import java.lang.reflect.Field;
import java.security.NoSuchAlgorithmException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.concurrent.atomic.AtomicReference;

import com.bonc.common.utils.*;
import net.sf.json.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.bonc.common.param.BaseParam;
import com.bonc.modules.business.entity.TbCommonParamInfoEntity;
import com.bonc.modules.business.entity.TbWorkOederDistributionEntity;
import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.HttpRequestMethodNotSupportedException;
import org.springframework.web.bind.annotation.*;

import com.bonc.modules.business.entity.TbWorkOrderInfoEntity;
import com.bonc.modules.business.service.TbWorkOrderInfoService;


/**
 * 工单信息码表
 *
 * @author feiniao
 * @date 2021-10-11 11:15:50
 */
@RestController
@RequestMapping("business/tbworkorderinfo")
public class TbWorkOrderInfoController {
    @Autowired
    private TbWorkOrderInfoService tbWorkOrderInfoService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("business:tbworkorderinfo:list")
    public Result list(@RequestParam Map<String, Object> params){
        PageUtils page = tbWorkOrderInfoService.queryPage(params);

        return Result.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{identifier}")
    //@RequiresPermissions("business:tbworkorderinfo:info")
    public Result info(@PathVariable("identifier") String identifier){
		TbWorkOrderInfoEntity tbWorkOrderInfo = tbWorkOrderInfoService.getById(identifier);

        return Result.ok().put("tbWorkOrderInfo", tbWorkOrderInfo);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("business:tbworkorderinfo:save")
    public Result save(@RequestBody TbWorkOrderInfoEntity tbWorkOrderInfo){
		tbWorkOrderInfoService.save(tbWorkOrderInfo);

        return Result.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("business:tbworkorderinfo:update")
    public Result update(@RequestBody TbWorkOrderInfoEntity tbWorkOrderInfo){
		tbWorkOrderInfoService.updateById(tbWorkOrderInfo);

        return Result.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("business:tbworkorderinfo:delete")
    public Result delete(@RequestBody String[] identifiers){
		tbWorkOrderInfoService.removeByIds(Arrays.asList(identifiers));

        return Result.ok();
    }

    /**
     * 工单查询接口
     * @param tbCommonParamValue
     * @return
     */
    @ExceptionHandler(HttpRequestMethodNotSupportedException.class)
    @PostMapping("/QueryCSS")
    public ReplyCommon QueryCSS(@RequestBody @Validated(BaseParam.list.class) TbCommonParamInfoEntity tbCommonParamValue) throws IllegalAccessException, UnsupportedEncodingException, NoSuchAlgorithmException {
        ReplyCommon res = tbWorkOrderInfoService.QueryCSS(tbCommonParamValue);
        return res;
    }

    /**
     * 省端调用集团查询接口
     */
    @RequestMapping("/QueryCSService")
    public Result getQueryCSService(@RequestBody TbWorkOrderInfoEntity orderInfo){
        AtomicReference<String> res = tbWorkOrderInfoService.postOrderInfoService(orderInfo.getIdentifier());
        return Result.ok().put("data",res);
    }

}
